package com.spring.sunflower.conversation

import com.spring.sunflower.base.BaseObserver
import com.spring.sunflower.base.BasePresenter
import com.spring.sunflower.bean.BlackHasBean
import com.spring.sunflower.bean.CommonBean
import com.spring.sunflower.bean.LabelBean

/**
 * Created by Kevin on 2021/8/18<br/>
 *
 * Describe:<br/>
 */
class ChatCommentPresenter(baseView: ConversationContract.ChatCommentView) :
    BasePresenter<ConversationContract.ChatCommentView>(baseView) {
    fun getReportType() {
        val observable = requestDataSource.requestLabel("accusationType")
        addDisposable(observable, object : BaseObserver<LabelBean?>(baseView) {
            override fun onSuccess(bean: LabelBean?) {
//                baseView.hideLoading();
                baseView.showReportType(bean!!.datas)
            }

            override fun onError(status: Int, msg: String) {}
        })
    }
    fun getHasBlacked(blackMemberId: String, operatorId: String) {
        val observable = requestDataSource.requestHasBlack(blackMemberId, operatorId)
        addDisposable(observable, object : BaseObserver<BlackHasBean>() {
            override fun onSuccess(bean: BlackHasBean) {
                val datas = bean.datas.data
                if ("0" == datas) {
                    baseView.hasBlacked(false)
                } else {
                    baseView.hasBlacked(true)
                }
            }

            override fun onError(status: Int, msg: String) {}
        })
    }

    fun blackAdd(blackRememberId: String) {
        val observable = requestDataSource.requestAddBlack(blackRememberId)
        addDisposable(observable, object : BaseObserver<CommonBean>(baseView) {
            override fun onSuccess(bean: CommonBean) {
                baseView.blackAddSuccess()
            }

            override fun onError(status: Int, msg: String) {
                baseView.blackAddFailed()
            }
        })
    }

    fun blackRemove(blackRememberId: String) {
        val observable = requestDataSource.requestRemoveBlack(blackRememberId)
        addDisposable(observable, object : BaseObserver<CommonBean>(baseView) {
            override fun onSuccess(bean: CommonBean) {
                baseView.blackRemoveSuccess()
            }

            override fun onError(status: Int, msg: String) {
                baseView.blackRemoveFailed()
            }
        })
    }

    fun getHasFollowed(anchorId: String) {
        val observable = requestDataSource.requestFollowedHas(anchorId)
        addDisposable(observable, object : BaseObserver<CommonBean>() {
            override fun onSuccess(bean: CommonBean) {
                val datas = bean.datas
                if ("1" == datas) {
                    baseView.hasFollowed(true)
                } else {
                    baseView.hasFollowed(false)
                }
            }

            override fun onError(status: Int, msg: String) {}
        })
    }

    fun setFollowed(anchorId: String, set: String) {
        val observable = requestDataSource.requestFollowedSet(anchorId, set)
        addDisposable(observable, object : BaseObserver<CommonBean>(baseView) {
            override fun onSuccess(bean: CommonBean) {
                baseView.setFollowedSuccess()
            }

            override fun onError(status: Int, msg: String) {
                baseView.setFollowedFailed()
            }
        })
    }
}